<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/bootstrap/dist/css/bootstrap.min.css">
    <style>
        p:not(:empty) {
            padding: 15px;
        }
        
        .container {
            padding-top: 100px;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="form-group">
            <label for="">邮箱地址</label>
            <input type="email" class="form-control" placeholder="请输入邮箱地址" id="email">
        </div>
        <!-- 错误bg-danger 正确bg-success -->
        <p id="info"></p>
    </div>
    <script src="/js/ajax.js">
    </script>
    <script>
        var emailInp = document.querySelector('#email');
        var info = document.querySelector('#info');

        emailInp.addEventListener('blur', function() {
            //获取用户输入的邮箱地址
            var email = this.value;
            //验证邮箱地址的正则表达式
            var reg = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.]+[A-Za-z\d]{2,4}&)/;
            //如果用户输入的邮箱地址不符合规则
            if (!reg.test(email)) {
                info.innerHTML = '请输入符合规则的邮箱地址';
                //让提示信息显示为错误提示的样式
                info.className = 'bg-danger';
                //阻止程序向下执行
                return;
            }
            //向服务端
            ajax({
                type: 'get',
                url: 'http://localhost:3000/verifyEmalAdress',
                data: {
                    email: email
                },
                success: function(result) {
                    console.log(result);
                },
                error: function(result) {
                    console.log(result);
                }
            });

        })
    </script>
</body>

</html>